home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / EmacsTeX / Emacs-3.0.1 / Source / lisp.el < prev    next >
Encoding:
Text File  |  1995-06-12  |  41.1 KB  |  1,199 lines

  1. ;; Mouse handling for NeXT "Emacs" front end.
  2. ;; Ripped off of sun-mouse.el
  3. ;; Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. ;; This file is NOT part of the standard GNU Emacs distribution.
  6.  
  7. ;; GNU Emacs is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  9. ;; accepts responsibility to anyone for the consequences of using it
  10. ;; or for whether it serves any particular purpose or works at all,
  11. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  12. ;; License for full details.
  13.  
  14. ;; Everyone is granted permission to copy, modify and redistribute
  15. ;; GNU Emacs, but only under the conditions described in the
  16. ;; GNU Emacs General Public License.   A copy of this license is
  17. ;; supposed to have been given to you along with GNU Emacs so you
  18. ;; can know your rights and responsibilities.  It should be in a
  19. ;; file named COPYING.  Among other things, the copyright notice
  20. ;; and this notice must be preserved on all copies.
  21.  
  22. ;;; converted from sun-mouse.el by John G. Myers, Feb 1990.
  23. ;;; sun-mouse by Jeff Peck, Sun Microsystems, Jan 1987.
  24. ;;; Original idea by Stan Jefferson
  25.  
  26. ;;(provide 'eterm-mouse)
  27.  
  28. ;;;
  29. ;;;     Modelled after the GNUEMACS keymap interface.
  30. ;;;
  31. ;;; User Functions:
  32. ;;;   make-mousemap, copy-mousemap, 
  33. ;;;   define-mouse, global-set-mouse, local-set-mouse,
  34. ;;;   use-global-mousemap, use-local-mousemap,
  35. ;;;   mouse-lookup, describe-mouse-bindings
  36. ;;;
  37. ;;; Options:
  38. ;;;   scrollbar-width
  39. ;;;
  40.  
  41. (defvar scrollbar-width 5
  42.   "*The character width of the scrollbar.
  43. The cursor is deemed to be in the right edge scrollbar if it is this near the
  44. right edge, and more than two chars past the end of the indicated line.
  45. Setting to nil limits the scrollbar to the edge or vertical dividing bar.")
  46.  
  47. ;;;
  48. ;;; Mousemaps
  49. ;;;
  50. (defun make-mousemap ()
  51.   "Returns a new mousemap."
  52.   (cons 'mousemap nil))
  53.  
  54. (defun copy-mousemap (mousemap)
  55.   "Return a copy of mousemap."
  56.   (copy-alist mousemap))
  57.  
  58. (defun define-mouse (mousemap mouse-list def)
  59.   "Args MOUSEMAP, MOUSE-LIST, DEF.  Define MOUSE-LIST in MOUSEMAP as DEF.
  60. MOUSE-LIST is a list of atoms specifing a mouse hit according to these rules:
  61.   * One of these atoms specifies the active region of the definition.
  62.     text, scrollbar, modeline, minibuffer
  63.   * One or two or these atoms specify the button or button combination.
  64.         left, middle, right, double
  65.   * Any combination of these atoms specify the active shift keys.
  66.         control, shift, meta
  67.   * With a single unshifted button, you can add
  68.     up
  69.     to indicate an up-click.
  70. The atom `double' is used with a button designator to denote a double click.
  71. Two button chords are denoted by listing the two buttons.
  72. See eterm-mouse-handler for the treatment of the form DEF."
  73.   (mousemap-set (mouse-list-to-mouse-code mouse-list) mousemap def))
  74.  
  75. (defun global-set-mouse (mouse-list def)
  76.   "Give MOUSE-EVENT-LIST a local definition of DEF.
  77. See define-mouse for a description of MOUSE-EVENT-LIST and DEF.
  78. Note that if MOUSE-EVENT-LIST has a local definition in the current buffer,
  79. that local definition will continue to shadow any global definition."
  80.   (interactive "xMouse event: \nxDefinition: ")
  81.   (define-mouse current-global-mousemap mouse-list def))
  82.  
  83. (defun local-set-mouse (mouse-list def)
  84.   "Give MOUSE-EVENT-LIST a local definition of DEF.
  85. See define-mouse for a description of the arguments.
  86. The definition goes in the current buffer's local mousemap.
  87. Normally buffers in the same major mode share a local mousemap."
  88.   (interactive "xMouse event: \nxDefinition: ")
  89.   (if (null current-local-mousemap)
  90.       (setq current-local-mousemap (make-mousemap)))
  91.   (define-mouse current-local-mousemap mouse-list def))
  92.  
  93. (defun use-global-mousemap (mousemap)
  94.   "Selects MOUSEMAP as the global mousemap."
  95.   (setq current-global-mousemap mousemap))
  96.  
  97. (defun use-local-mousemap (mousemap)
  98.   "Selects MOUSEMAP as the local mousemap.
  99. nil for MOUSEMAP means no local mousemap."
  100.   (setq current-local-mousemap mousemap))
  101.  
  102.  
  103. ;;;
  104. ;;; Interface to the Mouse encoding defined in Emacstool.c
  105. ;;;
  106. ;;; Called when mouse-prefix is sent to emacs, additional
  107. ;;; information is read in as a list (button x y time-delta)
  108. ;;;
  109. ;;; First, some generally useful functions:
  110. ;;;
  111.  
  112. (defun logtest (x y)
  113.   "True if any bits set in X are also set in Y.
  114. Just like the Common Lisp function of the same name."
  115.   (not (zerop (logand x y))))
  116.  
  117.  
  118. ;;;
  119. ;;; Hit accessors.
  120. ;;;
  121.  
  122. (defconst em::ButtonBits 7)        ; Lowest 3 bits.
  123. (defconst em::ShiftmaskBits 56)        ; Second lowest 3 bits (56 = 63 - 7).
  124. (defconst em::DoubleBits 64)        ; Bit 7.
  125. (defconst em::UpBits 128)        ; Bit 8.
  126.  
  127. ;;; All the useful code bits
  128. (defmacro em::hit-code (hit)
  129.   (` (nth 0 (, hit))))
  130. ;;; The button, or buttons if a chord.
  131. (defmacro em::hit-button (hit)
  132.   (` (logand em::ButtonBits (nth 0 (, hit)))))
  133. ;;; The shift, control, and meta flags.
  134. (defmacro em::hit-shiftmask (hit)
  135.   (` (logand em::ShiftmaskBits (nth 0 (, hit)))))
  136. ;;; Set if a double click (but not a chord).
  137. (defmacro em::hit-double (hit)
  138.   (` (logand em::DoubleBits (nth 0 (, hit)))))
  139. ;;; Set on button release (as opposed to button press).
  140. (defmacro em::hit-up (hit)
  141.   (` (logand em::UpBits (nth 0 (, hit)))))
  142. ;;; Screen x position.
  143. (defmacro em::hit-x (hit) (list 'nth 1 hit))
  144. ;;; Screen y position.
  145. (defmacro em::hit-y (hit) (list 'nth 2 hit))
  146. ;;; Millisconds since last hit.
  147. (defmacro em::hit-delta (hit) (list 'nth 3 hit))
  148.  
  149. (defmacro em::hit-up-p (hit)        ; A predicate.
  150.   (` (not (zerop (em::hit-up (, hit))))))
  151.  
  152. ;;;
  153. ;;; Loc accessors.  for em::window-xy
  154. ;;;
  155. (defmacro em::loc-w (loc) (list 'nth 0 loc))
  156. (defmacro em::loc-x (loc) (list 'nth 1 loc))
  157. (defmacro em::loc-y (loc) (list 'nth 2 loc))
  158.  
  159. (defmacro eval-in-buffer (buffer &rest forms)
  160.   "Macro to switches to BUFFER, evaluates FORMS, returns to original buffer."
  161.   ;; When you don't need the complete window context of eval-in-window
  162.   (` (let ((StartBuffer (current-buffer)))
  163.     (unwind-protect
  164.     (progn
  165.       (set-buffer (, buffer))
  166.       (,@ forms))
  167.     (set-buffer StartBuffer)))))
  168.  
  169. (put 'eval-in-buffer 'lisp-indent-hook 1)
  170.  
  171. ;;; this is used extensively by sun-fns.el
  172. ;;;
  173. (defmacro eval-in-window (window &rest forms)
  174.   "Switch to WINDOW, evaluate FORMS, return to original window."
  175.   (` (let ((OriginallySelectedWindow (selected-window)))
  176.        (unwind-protect
  177.        (progn
  178.          (select-window (, window))
  179.          (,@ forms))
  180.      (select-window OriginallySelectedWindow)))))
  181. (put 'eval-in-window 'lisp-indent-hook 1)
  182.  
  183. ;;;
  184. ;;; handy utility, generalizes window_loop
  185. ;;;
  186.  
  187. ;;; It's a macro (and does not evaluate its arguments).
  188. (defmacro eval-in-windows (form &optional yesmini)
  189.   "Switches to each window and evaluates FORM.  Optional argument
  190. YESMINI says to include the minibuffer as a window.
  191. This is a macro, and does not evaluate its arguments."
  192.   (` (let ((OriginallySelectedWindow (selected-window)))
  193.        (unwind-protect 
  194.        (while (progn
  195.             (, form)
  196.             (not (eq OriginallySelectedWindow
  197.                  (select-window
  198.                   (next-window nil (, yesmini)))))))
  199.      (select-window OriginallySelectedWindow)))))
  200. (put 'eval-in-window 'lisp-indent-hook 0)
  201.  
  202. (defun move-to-loc (x y)
  203.   "Move cursor to window location X, Y.
  204. Handles wrapped and horizontally scrolled lines correctly."
  205.   (move-to-window-line y)
  206.   ;; window-line-end expects this to return the window column it moved to.
  207.   (let ((cc (current-column))
  208.     (nc (move-to-column
  209.          (if (zerop (window-hscroll))
  210.          (+ (current-column)
  211.             (min (- (window-width) 2)    ; To stay on the line.
  212.              x))
  213.            (+ (window-hscroll) -1
  214.           (min (1- (window-width))    ; To stay on the line.
  215.                x))))))
  216.     (- nc cc)))
  217.  
  218.  
  219. (defun minibuffer-window-p (window)
  220.   "True iff this WINDOW is minibuffer."
  221.   (= (screen-height)
  222.      (nth 3 (window-edges window))    ; The bottom edge.
  223.      ))
  224.  
  225.  
  226. (defun eterm-mouse-handler (&optional hit)
  227.   "Evaluates the function or list associated with a mouse hit.
  228. Expecting to read a hit, which is a list: (button x y unused).  
  229. A form bound to button by define-mouse is found by mouse-lookup. 
  230. The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound.  
  231. If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*,
  232. *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp),
  233. the form is eval'ed; if the form is neither of these, it is an error.
  234. Returns nil."
  235.   (interactive)
  236.   (if (null hit) (setq hit (mouse-hit-read)))
  237.   (let ((loc (em::window-xy (em::hit-x hit) (em::hit-y hit))))
  238.     (let ((*mouse-window* (em::loc-w loc))
  239.       (*mouse-x* (em::loc-x loc))
  240.       (*mouse-y* (em::loc-y loc))
  241.       (mouse-code (mouse-event-code hit loc)))
  242.       (let ((form (eval-in-buffer (window-buffer *mouse-window*)
  243.             (mouse-lookup mouse-code))))
  244.     (cond ((null form)
  245.            (if (not (em::hit-up-p hit))    ; undefined up hits are ok.
  246.            (error "Undefined mouse event: %s" 
  247.               (prin1-to-string 
  248.                (mouse-code-to-mouse-list mouse-code)))))
  249.           ((symbolp form)
  250.            (setq this-command form)
  251.            (funcall form *mouse-window* *mouse-x* *mouse-y*))
  252.           ((listp form)
  253.            (setq this-command (car form))
  254.            (eval form))
  255.           (t
  256.            (error "Mouse action must be symbol or list, but was: %s"
  257.               form))))))
  258.   ;; Don't let 'eterm-mouse-handler get on last-command,
  259.   ;; since this function should be transparent.
  260.   (if (eq this-command 'eterm-mouse-handler)
  261.       (setq this-command last-command))
  262.   ;; (message (prin1-to-string this-command))    ; to see what your buttons did
  263.   nil)
  264.  
  265. (defun mouse-hit-read ()
  266.   "Read mouse-hit list from keyboard.  Like (read 'read-char),
  267. but that uses minibuffer, and mucks up last-command."
  268.   (let ((char-list nil) (char nil))
  269.     (while (not (equal 13        ; Carriage return.
  270.                (prog1 (setq char (read-char)) 
  271.              (setq char-list (cons char char-list))))))
  272.     (read (mapconcat 'char-to-string (nreverse char-list) ""))
  273.     ))
  274.  
  275.  
  276. (defun em::window-xy (x y)
  277.   "Find window containing screen coordinates X and Y.
  278. Returns list (window x y) where x and y are relative to window."
  279.   (or
  280.    (catch 'found
  281.      (eval-in-windows 
  282.       (let ((we (window-edges (selected-window))))
  283.     (let ((le (nth 0 we))
  284.           (te (nth 1 we))
  285.           (re (nth 2 we))
  286.           (be (nth 3 we)))
  287.       (if (= re (screen-width))
  288.           ;; include the continuation column with this window
  289.           (setq re (1+ re)))
  290.       (if (= be (screen-height))
  291.           ;; include partial line at bottom of screen with this window
  292.           ;; id est, if window is not multple of char size.
  293.           (setq be (1+ be)))
  294.  
  295.       (if (and (>= x le) (< x re)
  296.            (>= y te) (< y be))
  297.           (throw 'found 
  298.              (list (selected-window) (- x le) (- y te))))))
  299.       t))                ; include minibuffer in eval-in-windows
  300.    ;;If x,y from a real mouse click, we shouldn't get here.
  301.    (list nil x y)
  302.    ))
  303.  
  304. (defun em::window-region (loc)
  305.   "Parse LOC into a region symbol.
  306. Returns one of (text scrollbar modeline minibuffer)"
  307.   (let ((w (em::loc-w loc))
  308.     (x (em::loc-x loc))
  309.     (y (em::loc-y loc)))
  310.     (let ((right (1- (window-width w)))
  311.       (bottom (1- (window-height w))))
  312.       (cond ((minibuffer-window-p w) 'minibuffer)
  313.         ((>= y bottom) 'modeline)
  314.         ((>= x right) 'scrollbar)
  315.         ;; far right column (window seperator) is always a scrollbar
  316.         ((and scrollbar-width
  317.           ;; mouse within scrollbar-width of edge.
  318.           (>= x (- right scrollbar-width))
  319.           ;; mouse a few chars past the end of line.
  320.           (>= x (+ 2 (window-line-end w x y))))
  321.          'scrollbar)
  322.         (t 'text)))))
  323.  
  324. (defun window-line-end (w x y)
  325.   "Return WINDOW column (ignore X) containing end of line Y"
  326.   (eval-in-window w (save-excursion (move-to-loc (screen-width) y))))
  327.  
  328. ;;;
  329. ;;; The encoding of mouse events into a mousemap.
  330. ;;; These values must agree with coding in emacstool:
  331. ;;;
  332. (defconst em::keyword-alist 
  333.   '((left . 1) (middle . 2) (right . 4)
  334.     (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128)
  335.     (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048)
  336.     ))
  337.  
  338. (defun mouse-event-code (hit loc)
  339.   "Maps MOUSE-HIT and LOC into a mouse-code."
  340. ;;;Region is a code for one of text, modeline, scrollbar, or minibuffer.
  341.   (logior (em::hit-code hit)
  342.       (mouse-region-to-code (em::window-region loc))))
  343.  
  344. (defun mouse-region-to-code (region)
  345.   "Returns partial mouse-code for specified REGION."
  346.   (cdr (assq region em::keyword-alist)))
  347.  
  348. (defun mouse-list-to-mouse-code (mouse-list)
  349.   "Map a MOUSE-LIST to a mouse-code."
  350.   (apply 'logior
  351.      (mapcar (function (lambda (x)
  352.                  (cdr (assq x em::keyword-alist))))
  353.           mouse-list)))
  354.  
  355. (defun mouse-code-to-mouse-list (mouse-code)
  356.   "Map a MOUSE-CODE to a mouse-list."
  357.   (apply 'nconc (mapcar
  358.          (function (lambda (x)
  359.                  (if (logtest mouse-code (cdr x))
  360.                  (list (car x)))))
  361.          em::keyword-alist)))
  362.  
  363. (defun mousemap-set (code mousemap value)
  364.   (let* ((alist (cdr mousemap))
  365.      (assq-result (assq code alist)))
  366.     (if assq-result
  367.     (setcdr assq-result value)
  368.       (setcdr mousemap (cons (cons code value) alist)))))
  369.  
  370. (defun mousemap-get (code mousemap)
  371.   (cdr (assq code (cdr mousemap))))
  372.  
  373. (defun mouse-lookup (mouse-code)
  374.   "Look up MOUSE-EVENT and return the definition. nil means undefined."
  375.   (or (mousemap-get mouse-code current-local-mousemap)
  376.       (mousemap-get mouse-code current-global-mousemap)))
  377.  
  378. ;;;
  379. ;;; I (jpeck) don't understand the utility of the next four functions
  380. ;;; ask Steven Greenbaum <froud@kestrel>
  381. ;;;
  382. (defun mouse-mask-lookup (mask list)
  383.   "Args MASK (a bit mask) and LIST (a list of (code . form) pairs).
  384. Returns a list of elements of LIST whose code or'ed with MASK is non-zero."
  385.   (let ((result nil))
  386.     (while list
  387.       (if (logtest mask (car (car list)))
  388.       (setq result (cons (car list) result)))
  389.       (setq list (cdr list)))
  390.     result))
  391.  
  392. (defun mouse-union (l l-unique)
  393.   "Return the union of list of mouse (code . form) pairs L and L-UNIQUE,
  394. where L-UNIQUE is considered to be union'ized already."
  395.   (let ((result l-unique))
  396.     (while l
  397.       (let ((code-form-pair (car l)))
  398.     (if (not (assq (car code-form-pair) result))
  399.         (setq result (cons code-form-pair result))))
  400.       (setq l (cdr l)))
  401.     result))
  402.  
  403. (defun mouse-union-first-prefered (l1 l2)
  404.   "Return the union of lists of mouse (code . form) pairs L1 and L2,
  405. based on the code's, with preference going to elements in L1."
  406.   (mouse-union l2 (mouse-union l1 nil)))
  407.  
  408. (defun mouse-code-function-pairs-of-region (region)
  409.   "Return a list of (code . function) pairs, where each code is
  410. currently set in the REGION."
  411.   (let ((mask (mouse-region-to-code region)))
  412.     (mouse-union-first-prefered
  413.      (mouse-mask-lookup mask (cdr current-local-mousemap))
  414.      (mouse-mask-lookup mask (cdr current-global-mousemap))
  415.      )))
  416.  
  417. ;;;
  418. ;;; Functions for DESCRIBE-MOUSE-BINDINGS
  419. ;;; And other mouse documentation functions
  420. ;;; Still need a good procedure to print out a help sheet in readable format.
  421. ;;;
  422.  
  423. (defun one-line-doc-string (function)
  424.   "Returns first line of documentation string for FUNCTION.
  425. If there is no documentation string, then the string
  426. \"No documentation\" is returned."
  427.   (while (consp function) (setq function (car function)))
  428.   (let ((doc (documentation function)))
  429.     (if (null doc)
  430.     "No documentation."
  431.       (string-match "^.*$" doc)
  432.       (substring doc 0 (match-end 0)))))
  433.  
  434. (defun print-mouse-format (binding)
  435.   (princ (car binding))
  436.   (princ ": ")
  437.   (mapcar (function
  438.        (lambda (mouse-list)
  439.          (princ mouse-list)
  440.          (princ " ")))
  441.       (cdr binding))
  442.   (terpri)
  443.   (princ "  ")
  444.   (princ (one-line-doc-string (car binding)))
  445.   (terpri)
  446.   )
  447.  
  448. (defun print-mouse-bindings (region)
  449.   "Prints mouse-event bindings for REGION."
  450.   (mapcar 'print-mouse-format (em::event-bindings region)))
  451.  
  452. (defun em::event-bindings (region)
  453.   "Returns an alist of (function . (mouse-list1 ... mouse-listN)) for REGION,
  454. where each mouse-list is bound to the function in REGION."
  455.   (let ((mouse-bindings (mouse-code-function-pairs-of-region region))
  456.     (result nil))
  457.     (while mouse-bindings
  458.       (let* ((code-function-pair (car mouse-bindings))
  459.          (current-entry (assoc (cdr code-function-pair) result)))
  460.     (if current-entry
  461.         (setcdr current-entry
  462.             (cons (mouse-code-to-mouse-list (car code-function-pair))
  463.               (cdr current-entry)))
  464.       (setq result (cons (cons (cdr code-function-pair)
  465.                    (list (mouse-code-to-mouse-list
  466.                       (car code-function-pair))))
  467.                  result))))
  468.       (setq mouse-bindings (cdr mouse-bindings))
  469.       )
  470.     result))
  471.  
  472. (defun describe-mouse-bindings ()
  473.   "Lists all current mouse-event bindings."
  474.   (interactive)
  475.   (with-output-to-temp-buffer "*Help*"
  476.     (princ "Text Region") (terpri)
  477.     (princ "---- ------") (terpri)
  478.     (print-mouse-bindings 'text) (terpri)
  479.     (princ "Modeline Region") (terpri)
  480.     (princ "-------- ------") (terpri)
  481.     (print-mouse-bindings 'modeline) (terpri)
  482.     (princ "Scrollbar Region") (terpri)
  483.     (princ "--------- ------") (terpri)
  484.     (print-mouse-bindings 'scrollbar)))
  485.  
  486. (defun describe-mouse-briefly (mouse-list)
  487.   "Print a short description of the function bound to MOUSE-LIST."
  488.   (interactive "xDescibe mouse list briefly: ")
  489.   (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list))))
  490.     (if function
  491.     (message "%s runs the command %s" mouse-list function)
  492.       (message "%s is undefined" mouse-list))))
  493.  
  494.  
  495. ;;;
  496. ;;; initialize mouse maps
  497. ;;;
  498.  
  499. (make-variable-buffer-local 'current-local-mousemap)
  500. (setq-default current-local-mousemap nil)
  501. (defvar current-global-mousemap (make-mousemap))
  502.  ;; Low-level subroutines for NeXT "Emacs" front end
  503.  ;; Copyright (C) 1990 Free Software Foundation, Inc.
  504.  
  505.  ;; This file is NOT part of the standard GNU Emacs distribution.
  506.  
  507.  ;; GNU Emacs is distributed in the hope that it will be useful,
  508.  ;; but WITHOUT ANY WARRANTY.  No author or distributor
  509.  ;; accepts responsibility to anyone for the consequences of using it
  510.  ;; or for whether it serves any particular purpose or works at all,
  511.  ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  512.  ;; License for full details.
  513.  
  514.  ;; Everyone is granted permission to copy, modify and redistribute
  515.  ;; GNU Emacs, but only under the conditions described in the
  516.  ;; GNU Emacs General Public License.   A copy of this license is
  517.  ;; supposed to have been given to you along with GNU Emacs so you
  518.  ;; can know your rights and responsibilities.  It should be in a
  519.  ;; file named COPYING.  Among other things, the copyright notice
  520.  ;; and this notice must be preserved on all copies.
  521.  
  522.  ;;; Apr 4 '90 jgm    Ripped off of sun-fns.el
  523.  
  524.  ;;(provide 'eterm-low)
  525.  
  526.  (defun eterm-send-terminal-string-function (string function)
  527.    "Send a \\C-q quoted string to the terminal, then send function"
  528.    (send-string-to-terminal (concat "\C-q" string "\377" function)))
  529.  
  530.  (defun eterm-change-title (title)
  531.    "Change the wm title for the gnumacs window."
  532.    (interactive "sTitle: ")
  533.    (eterm-send-terminal-string-function title "t"))
  534.  
  535.  ;(defun global-set-menu (item command)
  536.  ;  "Add a command to the wm menus."
  537.  ;  (interactive "sMenu item: \nCCommand: ")
  538.  ;  (eterm-send-terminal-string-function
  539.  ;   (concat item ":\C-[x" (prin1-to-string command) "\n") "m"))
  540.  ;
  541.  ;(defun global-unset-menu (item)
  542.  ;  "Remove a menu item from the wm menus."
  543.  ;  (interactive "sMenu item: ")
  544.  ;  (eterm-send-terminal-string-function item "m"))
  545.  ;
  546.  ;(defun add-menu-item (item binding &optional page)
  547.  ;  "Add a menu item to the menus.  (obsolete)"
  548.  ;  (interactive "sItem: \nsBinding: \nsPage: ")
  549.  ;  (eterm-send-terminal-string-function
  550.  ;   (concat page (and page ", ")
  551.  ;       item (and binding (not (string= binding "")) ":") binding)
  552.  ;   "m"))
  553.  ;
  554.  ;(defun remove-menu-item (item &optional page)
  555.  ;  "Remove ITEM from the wm menus.  (obsolete)"
  556.  ;  (interactive "sItem: \nsPage:")
  557.  ;  (add-menu-item item "" page))
  558.  
  559.  ; something to hide without using the mouse
  560.  ;(defun eterm-hide-emacs ()
  561.  ;  "Ask the termulator to hide this window."
  562.  ;  (interactive)
  563.  ;  (send-string-to-terminal "\C-z"))
  564.  
  565.  ; cut buffer stuff
  566.  
  567.  (defun eterm-send-region-to-cut-buffer ()
  568.    "   Copy the region between point and mark to the NeXT cut buffer.
  569.     This will not happen if the region contains a \\377."
  570.    (interactive "")
  571.    (save-excursion
  572.      ;; We get our own values for the region, so we can trap the error
  573.      ;; if there is none.
  574.      (condition-case err
  575.      (let ((start (region-beginning))
  576.            (end (region-end)))
  577.        (goto-char start)
  578.        (if (search-forward "\377" end t)
  579.            (progn
  580.          (eterm-send-terminal-string-function "" "c")
  581.          (message "Bogus character in region."))
  582.          (eterm-send-terminal-string-function
  583.           (buffer-substring start end) "c")))
  584.        ;;
  585.        ;; The region is empty, send a nil region out and continue.
  586.        (error (eterm-send-terminal-string-function "" "c")))))
  587.  
  588. (defun eterm-send-region-to-cut-buffer-and-wipe ()
  589.   "  As send-region-to-cut-buffer but also kill the text."
  590.   (interactive "")
  591.   (barf-if-buffer-read-only)
  592.   (eterm-send-region-to-cut-buffer)
  593.   (call-interactively 'kill-region))
  594.  
  595. ;
  596. ; Event server stuff
  597. ;
  598.  
  599. (defvar eserver nil 
  600.   "The event server process.")
  601.  
  602. (defun start-event-server ()
  603.   (interactive)
  604.   (eterm-change-title (concat "Emacs version " emacs-version))
  605.   (let ((host (or (getenv "EVENT_HOST")
  606.           (error "Can't find host for event server")))
  607.     (port (or (getenv "EVENT_PORT")
  608.           (error "Can't find port for event server"))))
  609.     (setq eserver 
  610.       (open-network-stream " event-server" nil host
  611.                    (string-to-int port))))
  612.   (set-process-filter eserver 'event-filter)
  613.   (set-process-sentinel eserver 'event-sentinel)
  614.   (global-set-key "\C-x\C-@" 'eterm-mouse-handler))
  615.  
  616. (defun event-sentinel (process change)
  617.   (message (concat  "The event handler has " change)))
  618.  
  619. (defvar event-partial-output ""
  620.   "Incomplete, unprocessed output from the event server")
  621.  
  622. ;;; Modified by J. Gregory 17-Oct-91.  Save match-end before match
  623. ;;; data gets crunched.
  624. (defun event-filter (process string)
  625.   ;; Add the incoming string to what we have:
  626.   (let ((events (concat event-partial-output string)))
  627.     ;; Each event is terminated with a newline.
  628.     ;; Process events until we run out of newlines.
  629.     (while (string-match "\n" events)    ;sets match-data
  630.       (let ((next (match-end 0)))
  631.     (eval (car (read-from-string events)))
  632.     (setq events (substring events next))))
  633.     ;; Set global to be what we have not yet processed
  634.     (setq event-partial-output events)))
  635.  
  636. ; Handlers for the events that get sent to us.
  637. ;
  638. (defun event-copy ()
  639.   (eterm-send-region-to-cut-buffer))
  640.  
  641. (defun event-cut ()
  642.   (eterm-send-region-to-cut-buffer-and-wipe))
  643.  
  644. (defun event-paste (str)
  645.   (barf-if-buffer-read-only)
  646.   (push-mark (point))
  647.   (insert str))
  648.  
  649. (defun event-quit ()
  650.   (save-buffers-kill-emacs)
  651.   (setq last-command 'save-buffers-kill-emacs))
  652.  
  653. ;(defun event-resize (newx newy)
  654. ;  (if (or (not (= (screen-width) newx))
  655. ;      (not (= (screen-height) newy)))
  656. ;      (progn
  657. ;    (set-screen-width newx)
  658. ;    (set-screen-height newy))
  659. ;    (redraw-display)))
  660.  
  661.  
  662. ;; Subroutines of Mouse handling for NeXT "Emacs" front end
  663. ;; Ripped off of the Sun windows support code
  664. ;; Copyright (C) 1987 Free Software Foundation, Inc.
  665.  
  666. ;; This file is NOT part of the standard GNU Emacs distribution.
  667.  
  668. ;; GNU Emacs is distributed in the hope that it will be useful,
  669. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  670. ;; accepts responsibility to anyone for the consequences of using it
  671. ;; or for whether it serves any particular purpose or works at all,
  672. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  673. ;; License for full details.
  674.  
  675. ;; Everyone is granted permission to copy, modify and redistribute
  676. ;; GNU Emacs, but only under the conditions described in the
  677. ;; GNU Emacs General Public License.   A copy of this license is
  678. ;; supposed to have been given to you along with GNU Emacs so you
  679. ;; can know your rights and responsibilities.  It should be in a
  680. ;; file named COPYING.  Among other things, the copyright notice
  681. ;; and this notice must be preserved on all copies.
  682.  
  683. ;;; Apr 4 '90 jgm    Ripped off of sun-fns.el
  684. ;;(provide 'eterm-fns)
  685. ;;(require 'eterm-mouse)
  686. ;;;
  687. ;;; Functions for manipulating via the mouse and mouse-map definitions
  688. ;;; for accessing them.  Also definitons of mouse menus.
  689. ;;; This file you should freely modify to reflect you personal tastes.
  690. ;;;
  691. ;;; First half of file defines functions to implement mouse commands,
  692. ;;; Don't delete any of those, just add what ever else you need.
  693. ;;; Second half of file defines mouse bindings, do whatever you want there.
  694.  
  695. ;;;
  696. ;;;         Mouse Functions.
  697. ;;;
  698. ;;; These functions follow the eterm-mouse-handler convention of being called
  699. ;;; with three arguements: (window x-pos y-pos)
  700. ;;; This makes it easy for a mouse executed command to know where the mouse is.
  701. ;;; Use the macro "eval-in-window" to execute a function 
  702. ;;; in a temporarily selected window.
  703. ;;;
  704. ;;; If you have a function that must be called with other arguments
  705. ;;; bind the mouse button to an s-exp that contains the necessary parameters.
  706. ;;; See "minibuffer" bindings for examples.
  707. ;;;
  708. (defconst cursor-pause-milliseconds 300
  709.   "*Number of milliseconds to display alternate cursor (usually the mark)")
  710.  
  711. (defun indicate-region (&optional pause)
  712.   "Bounce cursor to mark for cursor-pause-milliseconds and back again"
  713.   (or pause (setq pause cursor-pause-milliseconds))
  714.   (let ((times 0))
  715.     (exchange-point-and-mark)
  716.     (if (fboundp 'sit-for-millisecs)
  717.     (sit-for-millisecs pause)
  718.       (sit-for 1))
  719.     (exchange-point-and-mark)))
  720.  
  721. ;      (while (< times 20)
  722. ;    (sit-for 0)
  723. ;    (setq times (1+ times))))
  724.  
  725.  
  726. ;;;
  727. ;;; Text buffer operations
  728. ;;;
  729. (defun mouse-move-point (window x y)
  730.   "Move point to mouse cursor."
  731.   (select-window window)
  732.   (move-to-loc x y)
  733.   (if (memq last-command    ; support the mouse-copy/delete/yank
  734.         '(mouse-copy mouse-delete mouse-yank-move))
  735.       (setq this-command 'mouse-yank-move))
  736.   )
  737.  
  738. (defun mouse-set-mark (window x y)
  739.   "Set mark at mouse cursor."
  740.   (eval-in-window window    ;; use this to get the unwind protect
  741.     (let ((point (point)))
  742.       (move-to-loc x y)
  743.       (set-mark (point))
  744.       (goto-char point)
  745.       (indicate-region)))
  746.   )
  747.  
  748. (defun mouse-set-mark-and-select (window x y)
  749.   "Set mark at mouse cursor, and select that window."
  750.   (select-window window)
  751.   (mouse-set-mark window x y)
  752.   )
  753.  
  754. ;;;
  755. ;;; Simple mouse dragging stuff: marking with button up
  756. ;;;
  757.  
  758. (defvar *mouse-drag-window* nil)
  759. (defvar *mouse-drag-x* -1)
  760. (defvar *mouse-drag-y* -1)
  761.  
  762. (defun mouse-drag-move-point (window x y)
  763.   "Move point to mouse cursor, and allow dragging."
  764.   (mouse-move-point window x y)
  765.   (setq *mouse-drag-window* window
  766.     *mouse-drag-x* x
  767.     *mouse-drag-y* y))
  768.  
  769. (defun mouse-drag-set-mark (window x y)
  770.   "The up click handler that goes with mouse-drag-move-point.
  771. If mouse is in same WINDOW but at different X or Y than when
  772. mouse-drag-move-point was last executed, set the mark at mouse."
  773.   (if (and (eq *mouse-drag-window* window)
  774.        (not (and (equal *mouse-drag-x* x)
  775.              (equal *mouse-drag-y* y))))
  776.       (mouse-set-mark-and-select window x y)
  777.     (setq this-command last-command))    ; this was just an upclick no-op.
  778.   )
  779.  
  780. (defun mouse-select-or-drag-move-point (window x y)
  781.   "Select window if not selected, otherwise do mouse-drag-move-point."
  782.   (if (eq (selected-window) window)
  783.       (mouse-drag-move-point window x y)
  784.     (mouse-select-window window x y)))
  785.  
  786. ;;;
  787. ;;; esoteria:
  788. ;;;
  789. (defun mouse-exch-pt-and-mark (window x y)
  790.   "Exchange point and mark."
  791.   (select-window window)
  792.   (exchange-point-and-mark)
  793.   )
  794.  
  795. (defun mouse-call-kbd-macro (window x y)
  796.   "Invokes last keyboard macro at mouse cursor."
  797.   (mouse-move-point window x y)
  798.   (call-last-kbd-macro)
  799.   )
  800.  
  801. (defun mouse-mark-thing (window x y)
  802.   "Set point and mark to text object using syntax table.
  803. The resulting region is put in the NeXT pasteboard.
  804. Left or right Paren syntax marks an s-expression.  
  805. Clicking at the end of a line marks the line including a trailing newline.  
  806. If it doesn't recognize one of these it marks the character at point."
  807.   (mouse-move-point window x y)
  808.   (if (eobp) (open-line 1))
  809.   (let* ((char (char-after (point)))
  810.          (syntax (char-syntax char)))
  811.     (cond
  812.      ((eq syntax ?w)            ; word.
  813.       (forward-word 1)
  814.       (set-mark (point))
  815.       (forward-word -1))
  816.      ;; try to include a single following whitespace (is this a good idea?)
  817.      ;; No, not a good idea since inconsistent.
  818.      ;;(if (eq (char-syntax (char-after (mark))) ?\ )
  819.      ;;    (set-mark (1+ (mark))))
  820.      ((eq syntax ?\( )            ; open paren.
  821.       (mark-sexp 1))
  822.      ((eq syntax ?\) )            ; close paren.
  823.       (forward-char 1)
  824.       (mark-sexp -1)
  825.       (exchange-point-and-mark))
  826.      ((eolp)                ; mark line if at end.
  827.       (set-mark (1+ (point)))
  828.       (beginning-of-line 1))
  829.      (t                    ; mark character
  830.       (set-mark (1+ (point)))))
  831.     (indicate-region))            ; display region boundary.
  832.   )
  833.  
  834. (defun mouse-kill-thing (window x y)
  835.   "Kill thing at mouse, and put point there."
  836.   (mouse-mark-thing window x y)
  837.   (eterm-send-region-to-cut-buffer-and-wipe (region-beginning) (region-end))
  838.   )
  839.  
  840. (defun mouse-kill-thing-there (window x y)
  841.   "Kill thing at mouse, leave point where it was.
  842. See mouse-mark-thing for a description of the objects recognized."
  843.   (eval-in-window window 
  844.     (save-excursion
  845.       (mouse-mark-thing window x y)
  846.       (eterm-send-region-to-cut-buffer-and-wipe (region-beginning) (region-end))))
  847.   )
  848.  
  849. (defun mouse-save-thing (window x y &optional quiet)
  850.   "Put thing at mouse in kill ring.
  851. See mouse-mark-thing for a description of the objects recognized."
  852.   (mouse-mark-thing window x y)
  853.   (eterm-send-region-to-cut-buffer (region-beginning) (region-end))
  854.   (if (not quiet) (message "Thing saved"))
  855.   )
  856.  
  857. (defun mouse-save-thing-there (window x y &optional quiet)
  858.   "Put thing at mouse in kill ring, leave point as is.
  859. See mouse-mark-thing for a description of the objects recognized."
  860.   (eval-in-window window
  861.     (save-excursion
  862.       (mouse-save-thing window x y quiet))))
  863.  
  864. ;;;
  865. ;;; Mouse yanking...
  866. ;;;
  867. (defun mouse-copy-thing (window x y)
  868.   "Put thing at mouse in kill ring, yank to point.
  869. See mouse-mark-thing for a description of the objects recognized."
  870.   (setq last-command 'not-kill)     ;Avoids appending to previous kills.
  871.   (mouse-save-thing-there window x y t)
  872.   (yank)
  873.   (setq this-command 'yank))
  874.  
  875. (defun mouse-move-thing (window x y)
  876.   "Kill thing at mouse, yank it to point.
  877. See mouse-mark-thing for a description of the objects recognized."
  878.   (setq last-command 'not-kill)     ;Avoids appending to previous kills.
  879.   (mouse-kill-thing-there window x y)
  880.   (yank)
  881.   (setq this-command 'yank))
  882.  
  883. (defun mouse-yank-at-point (&optional window x y)
  884.   "Yank from kill-ring at point; then cycle thru kill ring."
  885.   (if (eq last-command 'yank)
  886.       (let ((before (< (point) (mark))))
  887.     (delete-region (point) (mark))
  888.     (rotate-yank-pointer 1)
  889.     (insert (car kill-ring-yank-pointer))
  890.     (if before (exchange-point-and-mark)))
  891.     (yank))
  892.   (setq this-command 'yank))
  893.  
  894. (defun mouse-yank-at-mouse (window x y)
  895.   "Yank from kill-ring at mouse; then cycle thru kill ring."
  896.   (mouse-move-point window x y)
  897.   (mouse-yank-at-point window x y))
  898.  
  899. (defun mouse-save/delete/yank (&optional window x y)
  900.   "Context sensitive save/delete/yank.
  901. Consecutive clicks perform as follows:
  902.     * first click saves region to kill ring,
  903.     * second click kills region,
  904.     * third click yanks from kill ring,
  905.     * subsequent clicks cycle thru kill ring.
  906. If mouse-move-point is performed after the first or second click,
  907. the next click will do a yank, etc.  Except for a possible mouse-move-point,
  908. this command is insensitive to mouse location."
  909.   (cond
  910.    ((memq last-command '(mouse-delete yank mouse-yank-move))    ; third+ click
  911.     (mouse-yank-at-point))
  912.    ((eq last-command 'mouse-copy)    ; second click
  913.     (kill-region (region-beginning) (region-end))
  914.     (setq this-command 'mouse-delete))
  915.    (t                    ; first click
  916.     (copy-region-as-kill (region-beginning) (region-end))
  917.     (message "Region saved")
  918.     (setq this-command 'mouse-copy))
  919.    ))
  920.  
  921.  
  922. (defun mouse-split-horizontally (window x y)
  923.   "Splits the window horizontally at mouse cursor."
  924.   (eval-in-window window (split-window-horizontally (1+ x))))
  925.  
  926. (defun mouse-split-vertically (window x y)
  927.   "Split the window vertically at the mouse cursor."
  928.   (eval-in-window window (split-window-vertically (1+ y))))
  929.  
  930. (defun mouse-select-window (window x y)
  931.   "Selects the window, restoring point."
  932.   (select-window window))
  933.  
  934. (defun mouse-delete-other-windows (window x y)
  935.   "Deletes all windows except the one mouse is in."
  936.   (delete-other-windows window))
  937.  
  938. (defun mouse-delete-window (window x y)
  939.   "Deletes the window mouse is in."
  940.   (delete-window window))
  941.  
  942. (defun mouse-undo (window x y)
  943.   "Invokes undo in the window mouse is in."
  944.   (eval-in-window window (undo)))
  945.  
  946. ;;;
  947. ;;; Scroll operations
  948. ;;;
  949.  
  950. ;;; The move-to-window-line is used below because otherwise
  951. ;;; scrolling a non-selected process window with the mouse, after
  952. ;;; the process has written text past the bottom of the window,
  953. ;;; gives an "End of buffer" error, and then scrolls.  The
  954. ;;; move-to-window-line seems to force recomputing where things are.
  955. (defun mouse-scroll-up (window x y)
  956.   "Scrolls the window upward."
  957.   (eval-in-window window (move-to-window-line 1) (scroll-up nil)))
  958.  
  959. (defun mouse-scroll-down (window x y)
  960.   "Scrolls the window downward."
  961.   (eval-in-window window (scroll-down nil)))
  962.  
  963. (defun mouse-scroll-proportional (window x y)
  964.   "Scrolls the window proportionally corresponding to window
  965. relative X divided by window width."
  966.   (eval-in-window window 
  967.     (if (>= x (1- (window-width)))
  968.     ;; When x is maximun (equal to or 1 less than window width),
  969.     ;; goto end of buffer.  We check for this special case
  970.     ;; becuase the calculated goto-char often goes short of the
  971.     ;; end due to roundoff error, and we often really want to go
  972.     ;; to the end.
  973.     (goto-char (point-max))
  974.       (progn
  975.     (goto-char (+ (point-min)    ; For narrowed regions.
  976.               (* x (/ (- (point-max) (point-min))
  977.                   (1- (window-width))))))
  978.     (beginning-of-line))
  979.       )
  980.     (what-cursor-position)        ; Report position.
  981.     ))
  982.  
  983. (defun mouse-line-to-top (window x y)
  984.   "Scrolls the line at the mouse cursor up to the top."
  985.   (eval-in-window window (scroll-up y)))
  986.  
  987. (defun mouse-top-to-line (window x y)
  988.   "Scrolls the top line down to the mouse cursor."
  989.   (eval-in-window window (scroll-down y)))
  990.  
  991. (defun mouse-line-to-bottom (window x y)
  992.   "Scrolls the line at the mouse cursor to the bottom."
  993.   (eval-in-window window (scroll-up (+ y (- 2 (window-height))))))
  994.  
  995. (defun mouse-bottom-to-line (window x y)
  996.   "Scrolls the bottom line up to the mouse cursor."
  997.   (eval-in-window window (scroll-down (+ y (- 2 (window-height))))))
  998.  
  999. (defun mouse-line-to-middle (window x y)
  1000.   "Scrolls the line at the mouse cursor to the middle."
  1001.   (eval-in-window window (scroll-up (- y -1 (/ (window-height) 2)))))
  1002.  
  1003. (defun mouse-middle-to-line (window x y)
  1004.   "Scrolls the line at the middle to the mouse cursor."
  1005.   (eval-in-window window (scroll-up (- (/ (window-height) 2) y 1))))
  1006.  
  1007.  
  1008.  
  1009. ;;;
  1010. ;;; minibuffer
  1011. ;;;
  1012. (defun mini-move-point (window x y)
  1013.   ;; -6 is good for most common cases
  1014.   (mouse-move-point window (- x 6) 0))
  1015.  
  1016. (defun mini-set-mark-and-select (window x y)
  1017.   ;; -6 is good for most common cases
  1018.   (mouse-set-mark-and-select window (- x 6) 0))
  1019.  
  1020.  
  1021. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  1022. ;;; Buffer-mode Mouse commands
  1023. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  1024.  
  1025. (defun Buffer-at-mouse (w x y)
  1026.   "Calls Buffer-menu-buffer from mouse click."
  1027.   (save-window-excursion 
  1028.     (mouse-move-point w x y)
  1029.     (beginning-of-line)
  1030.     (Buffer-menu-buffer t)))
  1031.  
  1032. (defun mouse-buffer-bury (w x y)
  1033.   "Bury the indicated buffer."
  1034.   (bury-buffer (Buffer-at-mouse w x y))
  1035.   )
  1036.  
  1037. (defun mouse-buffer-select (w x y)
  1038.   "Put the indicated buffer in selected window."
  1039.   (switch-to-buffer (Buffer-at-mouse w x y))
  1040.   (list-buffers)
  1041.   )
  1042.  
  1043. (defun mouse-buffer-delete (w x y)
  1044.   "mark indicated buffer for delete"
  1045.   (save-window-excursion
  1046.     (mouse-move-point w x y)
  1047.     (Buffer-menu-delete)
  1048.     ))
  1049.  
  1050. (defun mouse-buffer-execute (w x y)
  1051.   "execute buffer-menu selections"
  1052.   (save-window-excursion
  1053.     (mouse-move-point w x y)
  1054.     (Buffer-menu-execute)
  1055.     ))
  1056.   
  1057. (defun enable-mouse-in-buffer-list ()
  1058.   "Call this to enable mouse selections in *Buffer List*
  1059.     LEFT puts the indicated buffer in the selected window.
  1060.     SHIFT-LEFT buries the indicated buffer.
  1061.     RIGHT marks the indicated buffer for deletion.
  1062.     SHIFT-RIGHT deletes the marked buffers.
  1063. To unmark a buffer marked for deletion, select it with LEFT."
  1064.   (save-window-excursion
  1065.     (list-buffers)            ; Initialize *Buffer List*
  1066.     (set-buffer "*Buffer List*")
  1067.     (local-set-mouse '(text shift left) 'mouse-buffer-bury)
  1068.     (local-set-mouse '(text left) 'mouse-buffer-select)        
  1069.     (local-set-mouse '(text right) 'mouse-buffer-delete)
  1070.     (local-set-mouse '(text shift right) 'mouse-buffer-execute)
  1071.     )
  1072.   )
  1073.  
  1074.  
  1075. ;;;*******************************************************************
  1076. ;;;
  1077. ;;;           Global Mouse Bindings.
  1078. ;;;
  1079. ;;; There is some sense to this mouse binding madness:
  1080. ;;; LEFT and RIGHT scrolls are inverses.
  1081. ;;; SHIFT makes an opposite meaning in the scroll bar.
  1082. ;;; META makes the scrollbar functions work in the text region.
  1083. ;;; RIGHT operates the mark
  1084. ;;; LEFT operates at point
  1085.  
  1086. ;;; META commands are generally non-destructive,
  1087. ;;; SHIFT is a little more dangerous.
  1088. ;;; CONTROL is for the really complicated ones.
  1089.  
  1090. ;;; CONTROL-META-SHIFT-RIGHT gives help on that region.
  1091. ;;; (or so it would if I had time to implement it --jgm)
  1092.  
  1093. ;;;
  1094. ;;; Text Region mousemap
  1095. ;;;
  1096. ;; The basics: Point, Mark, Menu, Sun-Select:
  1097. (global-set-mouse '(text        left)    'mouse-drag-move-point)
  1098. (global-set-mouse '(text     up left)    'mouse-drag-set-mark)
  1099. (global-set-mouse '(text shift  left)    'mouse-exch-pt-and-mark)
  1100.  
  1101. (global-set-mouse '(text    right)    'mouse-set-mark-and-select)
  1102.  
  1103. ;; The Slymoblics multi-command for Save, Kill, Copy, Move:
  1104. (global-set-mouse '(text shift    right)    'mouse-save/delete/yank)
  1105.  
  1106. ;; Save, Kill, Copy, Move Things:
  1107. ;; control-left composes with control middle/right to produce copy/move
  1108. (global-set-mouse '(text control right        )    'mouse-save-thing-there)
  1109. ;(global-set-mouse '(text control right      )    'mouse-kill-thing-there)
  1110. (global-set-mouse '(text control     left)    'mouse-yank-at-point)
  1111.  
  1112. ;(global-set-mouse '(text control middle    left)    'mouse-copy-thing)
  1113. ;(global-set-mouse '(text control right    left)    'mouse-move-thing)
  1114. ;(global-set-mouse '(text control right middle)    'mouse-mark-thing)
  1115.  
  1116. ;; The Universal mouse help command (press all buttons):
  1117. ;(global-set-mouse '(text shift  control meta right)    'mouse-help-region)
  1118.  
  1119. ;;; Meta in Text Region is like meta version in scrollbar:
  1120. (global-set-mouse '(text meta        left)    'mouse-line-to-top)
  1121. (global-set-mouse '(text meta shift  left)    'mouse-line-to-bottom)
  1122. ;(global-set-mouse '(text meta         middle)    'mouse-line-to-middle)
  1123. ;(global-set-mouse '(text meta shift   middle)    'mouse-middle-to-line)
  1124. ;(global-set-mouse '(text meta control middle)    'mouse-split-vertically)
  1125. (global-set-mouse '(text meta        right)    'mouse-top-to-line)
  1126. (global-set-mouse '(text meta shift  right)    'mouse-bottom-to-line)
  1127.  
  1128. ;; Miscellaneous:
  1129. (global-set-mouse '(text meta control left)    'mouse-call-kbd-macro)
  1130. (global-set-mouse '(text meta control right)    'mouse-undo)
  1131.  
  1132. ;;;
  1133. ;;; Scrollbar mousemap.
  1134. ;;; Are available in the Scrollbar Region, or with Meta Text (or Meta Scrollbar)
  1135. ;;;
  1136. (global-set-mouse '(scrollbar        left)    'mouse-line-to-top)
  1137. (global-set-mouse '(scrollbar shift  left)    'mouse-line-to-bottom)
  1138.  
  1139. ;(global-set-mouse '(scrollbar         middle)    'mouse-line-to-middle)
  1140. ;(global-set-mouse '(scrollbar shift   middle)    'mouse-middle-to-line)
  1141. ;(global-set-mouse '(scrollbar control middle)    'mouse-split-vertically)
  1142.  
  1143. (global-set-mouse '(scrollbar        right)    'mouse-top-to-line)
  1144. (global-set-mouse '(scrollbar shift  right)    'mouse-bottom-to-line)
  1145.  
  1146. (global-set-mouse '(scrollbar meta        left)        'mouse-line-to-top)
  1147. (global-set-mouse '(scrollbar meta shift  left)        'mouse-line-to-bottom)
  1148. ;(global-set-mouse '(scrollbar meta         middle)    'mouse-line-to-middle)
  1149. ;(global-set-mouse '(scrollbar meta shift   middle)    'mouse-middle-to-line)
  1150. ;(global-set-mouse '(scrollbar meta control middle)    'mouse-split-vertically)
  1151. (global-set-mouse '(scrollbar meta        right)    'mouse-top-to-line)
  1152. (global-set-mouse '(scrollbar meta shift  right)    'mouse-bottom-to-line)
  1153.  
  1154. ;; And the help menu:
  1155. ;(global-set-mouse '(scrollbar shift  control meta right) 'mouse-help-region)
  1156.  
  1157. ;;;
  1158. ;;; Modeline mousemap.
  1159. ;;;
  1160. ;;; Note: meta of any single button selects window.
  1161.  
  1162. (global-set-mouse '(modeline      left)    'mouse-scroll-up)
  1163. (global-set-mouse '(modeline meta left)    'mouse-select-window)
  1164.  
  1165. ;(global-set-mouse '(modeline         middle)    'mouse-scroll-proportional)
  1166. ;(global-set-mouse '(modeline meta    middle)    'mouse-select-window)
  1167. ;(global-set-mouse '(modeline control middle)    'mouse-split-horizontally)
  1168.  
  1169. (global-set-mouse '(modeline      right)    'mouse-scroll-down)
  1170. (global-set-mouse '(modeline meta right)    'mouse-select-window)
  1171.  
  1172. ;;; control-left selects this window, control-right deletes it.
  1173. (global-set-mouse '(modeline control left)    'mouse-delete-other-windows)
  1174. (global-set-mouse '(modeline control right)    'mouse-delete-window)
  1175.  
  1176. ;; in case of confusion, just select it:
  1177. (global-set-mouse '(modeline control left right)'mouse-select-window)
  1178.  
  1179. ;; even without confusion (and without the keyboard) select it:
  1180. (global-set-mouse '(modeline left right)    'mouse-select-window)
  1181.  
  1182. ;; And the help menu:
  1183. ;(global-set-mouse '(modeline shift  control meta right)    'mouse-help-region)
  1184.  
  1185. ;;;
  1186. ;;; Minibuffer Mousemap
  1187. ;;; Demonstrating some variety:
  1188. ;;;
  1189. (global-set-mouse '(minibuffer left)        'mini-move-point)
  1190. (global-set-mouse '(minibuffer right)    'mini-set-mark-and-select)
  1191.  
  1192. (global-set-mouse '(minibuffer shift   left) '(previous-complex-command 1))
  1193. (global-set-mouse '(minibuffer control left) '(next-complex-command 1))
  1194.  
  1195. (global-set-mouse '(minibuffer shift   right) '(next-complex-command 1))
  1196. (global-set-mouse '(minibuffer control right) '(previous-complex-command 1))
  1197.  
  1198. ;(global-set-mouse '(minibuffer shift  control meta right)  'mouse-help-region)
  1199.